<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=big5" language="java" import="util.*, java.sql.*,beans.*" errorPage="" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Personal Payment Page</title>
    <link href="astyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="absolute_title">Captain Hook's Store</div>
<div class="absolute_title2">
    <h5>
        <%
        String username = (String)session.getAttribute("username");
        
        if(username==null) {
            response.sendRedirect("NotLoginPage.jsp");
        }else {
        
        %>
        <h5>Hi!<%= username%><br/>
        <a href="logout.jsp"> Click here to logout</a></h5>
        
    </h5>
</div>
<div class="wrap">
    <div class="canvas">
        <div class="left_column">
            <div class="header_left">
                <div class="header_leftrowone">&nbsp;</div>
                <div class="header_leftrowtwo"><img src="../image/cpt_hook_banner1.jpg" width="123" height="87" /></div>
                <div class="header_leftrowthree"></div>
            </div>
            <div class="leftnav">
                <ul>
                    <li></li>
                </ul>
            </div>
            <div>
                <SCRIPT src="displayMyFlash1.js"></SCRIPT>
            </div>
        </div>
        <div class="right_column">
            <div class="header_right">
                <div class="header_rightrowone">&nbsp;</div>
                <div class="header_rightrowtwo">&nbsp;</div>
                <div class="header_rightrowthree">
                    <ul class="topmenu">
                        <li><a title="Home" 
                               href="index.jsp">Home</a> | </li>
                        <li><a title="Information" 
                               href="companybackground.html">Information</a> | </li>
                        <li><a title="Forum" 
                               href="http://www.voy.com/206926/">Discussion Forum</a></li>
                    </ul>
                </div>
            </div>
            <div class="content_wrapper">
                <div class="content_left">
                    <div>
                    <h2>Payment Record</h2> 
                    <table width="100%" height="auto" border="1">
                        <tr bgcolor="white" height="50">
                            <td width="149">Payment ID</td>
                            <td width="149">Cardholder name</td>
                            <td width="116">CardNumber</td>
                            <td width="65">Bank</td>
                            <td width="105">Expiry Date</td>
                            <td width="96">Company</td>
                            <td width="90">Amount</td>
                            <td width="100">Date</td>
                            <td width="99">Time</td>
                            <td width="100">Purchased Items</td>
                        </tr>
                        <%
                        final String sPage = (String)request.getParameter("page");
                        int page1 = 0; //<====
                        
                        if(util.Utilities.isValid(sPage)) {
                            try {
                                page1 = Integer.parseInt(sPage);
                            } catch(Exception e) {
                                
                            }
                        }
                        PaymentBean[] payment = null;
                        try {
                            payment = PaymentBean.byUser(username);
                        } catch(Exception e) {
                            
                        }
                        final int k=page1;
                        
                        final int recordPerPage = 10;
                        final int indexPerPage =10;
                        final int count = payment.length; //<=======
                        final int indexCount = (int)Math.floor(count / (double)recordPerPage);
                        if(page1 > indexCount) {
                            page1 = 0;
                        }
                        
                        try {
                            for(int z=recordPerPage*page1; z<(page1+1)*recordPerPage; z++ ) {
                                
                                String userID = payment[z].getUserID();
                                String holdername = payment[z].getHoldername();
                                String number = payment[z].getNumber();
                                String bank = payment[z].getBank();
                                String issueDate = payment[z].getIssueDate();
                                String company = payment[z].getCompany();
                                String amount = payment[z].getAmount();
                                int paymentID = payment[z].getPaymentID();
                                String date = payment[z].getDate();
                                String time = payment[z].getTime();
                                String currency = payment[z].getCurrency();
                        %>
                        <tr height="50">
                            <td><%=paymentID%>
                                <input type='hidden' name='paymentID' value='<%=paymentID%>' />
                            </td>
                            <td><%=holdername%>
                                <input type='hidden' name='holdername' value='<%=holdername%>' />
                            </td>
                            <td><%=number%>
                                <input type='hidden' name='number' value='<%=number%>' />
                            </td>
                            <td><%=bank%>
                                <input type='hidden' name='bank' value='<%=bank%>' />
                            </td>
                            <td><%=issueDate%>
                                <input type='hidden' name='issueDate' value='<%=issueDate%>' />
                            </td>
                            <td><%=company%>
                                <input type='hidden' name='company' value='<%=company%>' />
                            </td>
                            <td> $<%=currency%>&nbsp;<%=amount%>
                                <input type='hidden' name='amount' value='<%=amount%>' />
                            </td>
                            <td><%=date%>
                                <input type='hidden' name='date' value='<%=date%>' />
                            </td>
                            <td><%=time%>
                                <input type='hidden' name='company' value='<%=time%>' />
                            </td>
                            <td><a href="PaymentDetail.jsp?paymentID=<%=paymentID%>">Items</a>
                                <input type='hidden' name='company' value='<%=time%>' />
                            </td>
                        </tr>
                        <%
                            }
                        }catch (Exception e) {
                            e.printStackTrace();
                        }
                        %>
                    </table>
                    </td>
                    </tr>
                    <%!                                
                    void printIndex(int k, int i, JspWriter out1) {
                        try {
                            if (i==k) {
                                out1.println("<b><a href='PersonalPayment.jsp?page="+i+"'>"+(i+1)+"</a></b>");
                            }else {
                                out1.println("<a href='PersonalPayment.jsp?page="+i+"'>"+(i+1)+"</a>");
                            }
                        }catch(Exception e) {
                            
                        }
                    }
                    
                    %>
                    <p>&nbsp;</p>
                    <div class="post_btm">
                        <form method='get' action='Catalogue.jsp'>
                            <center>
                                <%
                                int nextValue = 5;
                                int remain = count-(indexCount+page1);
                                if (remain < indexPerPage) {
                                    nextValue = remain % indexPerPage;
                                }
                                if(k < 5) {
                                    for(int i=0; i<=indexCount&&i<indexPerPage; i++) {
                                        printIndex(k, i, out);
                                    }
                                }else if(k >= indexCount-indexCount%indexPerPage -1) {
                                    int start = indexCount - indexPerPage;
                                    for(int y=0; y <indexPerPage; y++) {
                                        printIndex(k, y+start, out);
                                    }
                                }else {
                                    for (int i=0; i<5; i++) {
                                        printIndex(k, page1-5+i, out);
                                    }
                                    for (int i=0; i< 5&& page1+i<indexCount; i++) {
                                        printIndex(k, page1+i, out);
                                    }
                                }
                                %>
                                <input type='hidden' name='page' value='<%= k+1%>' />
                                <input name="submit" type = "submit" value='Next Page'/>
                            </center>
                        </form>
                    </div>
                </div>
            </div>
            <div class="footer">
                <ul class="basemenu">
                    <li></li>
                </ul>
                <% }
                %>
                Designed by Captain Hook inc, all rights reserved. <br />
            </div>
        </div>
    </div>
</div>
</body>
</html>
